package cn.edu.zafu.bigdata.lwg;

public class DivideExample {

    public static void main(String[] args) {
        try {
            int a = 10;
            int b = 0;
            double result = divide(a, b);
            System.out.println("结果是: " + result);
        } catch (ArithmeticException e) {
            System.out.println("错误：分母不能为0。");
        }
    }

    public static double divide(int a, int b) {
        if (b == 0) {
            // 如果b为0，则抛出ArithmeticException异常
            throw new ArithmeticException("除数不能为0");
        } else {
            // 正常计算除法
            return (double) a / b;
        }
    }
}